package top.vains.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.vains.dto.RolePermissionDto;
import top.vains.entity.Result;
import top.vains.service.IRolePermissionService;
import top.vains.util.ResultUtils;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author vains
 * @since 2020-02-17
 */
@RestController
@RequestMapping("/rolePermission")
@Api(tags = "角色权限接口，更新指定角色对应的权限")
public class RolePermissionController {

    private final IRolePermissionService rolePermissionService;

    @Autowired
    public RolePermissionController(IRolePermissionService rolePermissionService) {
        this.rolePermissionService = rolePermissionService;
    }

    @GetMapping("/getRolePermissionId")
    @ApiOperation(value = "获取角色对应的权限ID", notes = "获取角色对应的权限ID")
    public Result getRolePermissionId(Integer roleId) {
        List<Integer> permissionIds = rolePermissionService.getRolePermissionId(roleId);
        return ResultUtils.success("查询成功！", permissionIds);
    }

    @PutMapping("/updateRolePermissions")
    @ApiOperation(value = "更新角色对应的权限ID", notes = "更新角色对应的权限ID")
    public Result updateRolePermissions(@RequestBody RolePermissionDto rolePermissionDto) {
        rolePermissionService.updateRolePermissions(rolePermissionDto);
        return ResultUtils.success("更新成功！");
    }

}
